home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Include / FWCmd.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  7.3 KB  |  240 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWCmd.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWCMD_H
  11. #define FWCMD_H
  12.  
  13. // ----- Foundation Includes -----
  14.  
  15. #ifndef FWSTDDEF_H
  16. #include "FWStdDef.h"
  17. #endif
  18.  
  19. #ifndef FWEXCLIB_H
  20. #include "FWExcLib.h"
  21. #endif
  22.  
  23. // ----- OpenDoc Includes -----
  24.  
  25. // for ODName
  26. #ifndef _ODTYPES_
  27. #include <ODTypes.h>
  28. #endif
  29.  
  30. #ifndef SOM_ODUndo_xh
  31. #include <Undo.xh>
  32. #endif
  33.  
  34. #if FW_LIB_EXPORT_PRAGMAS
  35. #pragma lib_export on
  36. #endif
  37.  
  38. //==============================================================================
  39. //    Forward Declarations
  40. //==============================================================================
  41.  
  42. class FW_CLASS_ATTR FW_CPart;
  43. class FW_CLASS_ATTR FW_CFrame;
  44. class FW_CLASS_ATTR FW_CSelection;
  45. class FW_CLASS_ATTR FW_CString;
  46. class FW_CLASS_ATTR ODUndo;
  47.  
  48. //==============================================================================
  49. //    Constants
  50. //==============================================================================
  51.  
  52. #define FW_kCanUndo TRUE
  53. #define FW_kCantUndo FALSE
  54.  
  55. //==============================================================================
  56. // class FW_CCommand
  57. //==============================================================================
  58.  
  59. class FW_CLASS_ATTR FW_CCommand FW_AUTO_DESTRUCT_OBJECT
  60. {
  61.   public:
  62.     FW_DECLARE_CLASS
  63.  
  64.   public:
  65.  
  66. //------------------------------------------------------------------------
  67. // --- Initialization/Destruction ---
  68.  
  69.     FW_CCommand(Environment* ev,
  70.                 ODCommandID id,
  71.                 FW_CFrame* frame,
  72.                 FW_Boolean canUndo);
  73.     virtual ~ FW_CCommand();
  74.  
  75. //------------------------------------------------------------------------
  76. // --- Command API ---
  77.  
  78.     void PerformCommand(Environment* ev);
  79.         // Perform the command by calling DoIt, 
  80.         // and take care of OpenDoc Undo/Redo paperwork if necessary
  81.  
  82.     virtual void DoIt(Environment* ev) = 0;
  83.         // Must be overridden by all commands
  84.  
  85. //------------------------------------------------------------------------
  86. // --- API for Undo-able Commands ---
  87.  
  88.     virtual void UndoIt(Environment* ev);
  89.     virtual void RedoIt(Environment* ev);
  90.         // Undo-able commands must override
  91.         // Default does nothing
  92.  
  93.     virtual void CommitDone(Environment* ev);
  94.         // Called just before the command is deleted.
  95.         // doneState values are kODDone or kODRedone (ODTypes.h)
  96.         // Default calls FreeUndoState
  97.  
  98.     virtual void CommitUndone(Environment* ev);
  99.         // Called just before the command is deleted.
  100.         // doneState value is kODUndone (ODTypes.h)
  101.         // Default calls FreeRedoState
  102.  
  103.     virtual void SaveUndoState(Environment* ev);
  104.     virtual void SaveRedoState(Environment* ev);
  105.         // Save state of data for later undo and redo
  106.         // Default does nothing
  107.  
  108.     virtual void FreeUndoState(Environment* ev);
  109.     virtual void FreeRedoState(Environment* ev);
  110.         // Free data saved for undo and redo
  111.         // Default does nothing
  112.  
  113. //------------------------------------------------------------------------
  114. // --- New API ---
  115.  
  116.     ODActionType    GetActionType(Environment* ev) const;
  117.     FW_Boolean        GetCanUndo(Environment* ev) const;
  118.     FW_Boolean        GetCausesChange(Environment* ev) const;
  119.     ODCommandID        GetCommandID(Environment* ev) const;
  120.  
  121.     FW_Boolean        HasAddedAction(Environment* ev) const;
  122.  
  123.     void            SetActionType(Environment* ev, ODActionType actionType);
  124.     void            SetCausesChange(Environment* ev, FW_Boolean causesChange);
  125.  
  126.   protected:
  127.     void            SetMenuStrings(Environment* ev,
  128.                                    const FW_CString& undoString,
  129.                                    const FW_CString& redoString);
  130.     void            SetMenuStrings(Environment* ev,
  131.                                    char* undoChars,
  132.                                    char* redoChars);
  133.                     // Call one of these to set up menu strings for Undo and Redo
  134.  
  135.  
  136.     void            AddAction(Environment* ev, 
  137.                               ODActionType actionType, 
  138.                               octet* dataPtr, 
  139.                               unsigned long dataSize,
  140.                               ODName* undoActionLabel,
  141.                               ODName* redoActionLabel);
  142.                     // Call ODUndo::AddActionToHistory; used for transactions
  143.  
  144.     FW_Boolean        IsOKtoEdit(Environment* ev);
  145.                     // Checks whether it's OK to change this part and frame
  146.  
  147. private:
  148.     void            PrivDisposeUndoStrings();
  149.     
  150. //------------------------------------------------------------------------
  151. // --- Data Members ---
  152.  
  153.   protected:
  154.     ODCommandID        fCommandID;
  155.     FW_Boolean        fCanUndo;                // Default = TRUE
  156.     FW_Boolean        fCausesChange;            // Default = TRUE
  157.     ODActionType    fActionType;            // Default = kODSingleAction
  158.  
  159.     FW_CPart*        fPart;    
  160.     FW_CFrame*        fFrame;    
  161.     FW_CSelection*    fSelection;
  162.  
  163.     ODName*            fUndoString;            // string for Undo menu item
  164.     ODName*            fRedoString;            // string for Redo menu item
  165.  
  166.   private:
  167.     ODUndo*            fUndo;
  168.     FW_Boolean        fHasAddedAction;        // TRUE if this command has called AddAction
  169.  
  170.     // Don't allow commands to be copied or returned from functions
  171.     FW_CCommand(const FW_CCommand& command);            // Copy constructor
  172.     FW_CCommand& operator=(const FW_CCommand& command);    // Assignment operator
  173. };
  174.  
  175. //========================================================================================
  176. //    FW_CCommand Inlines
  177. //========================================================================================
  178.  
  179. //----------------------------------------------------------------------------------------
  180. //    FW_CCommand::GetActionType
  181. //----------------------------------------------------------------------------------------
  182. inline ODActionType FW_CCommand::GetActionType(Environment* ev) const
  183. {
  184.     return fActionType;
  185. }
  186.  
  187. //----------------------------------------------------------------------------------------
  188. //    FW_CCommand::GetCanUndo
  189. //----------------------------------------------------------------------------------------
  190. inline FW_Boolean FW_CCommand::GetCanUndo(Environment* ev) const
  191. {
  192.     return fCanUndo;
  193. }
  194.  
  195. //----------------------------------------------------------------------------------------
  196. //    FW_CCommand::GetCausesChange
  197. //----------------------------------------------------------------------------------------
  198. inline FW_Boolean FW_CCommand::GetCausesChange(Environment* ev) const
  199. {
  200.     return fCausesChange;
  201. }
  202.  
  203. //----------------------------------------------------------------------------------------
  204. //    FW_CCommand::GetCommandID
  205. //----------------------------------------------------------------------------------------
  206. inline ODCommandID FW_CCommand::GetCommandID(Environment* ev) const
  207. {
  208.     return fCommandID;
  209. }
  210.  
  211. //----------------------------------------------------------------------------------------
  212. //    FW_CCommand::HasAddedAction
  213. //----------------------------------------------------------------------------------------
  214. inline FW_Boolean FW_CCommand::HasAddedAction(Environment* ev) const
  215. {
  216.     return fHasAddedAction;
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. //    FW_CCommand::SetActionType
  221. //----------------------------------------------------------------------------------------
  222. inline void FW_CCommand::SetActionType(Environment* ev, ODActionType actionType)
  223. {
  224.     fActionType = actionType;
  225. }
  226.  
  227. //----------------------------------------------------------------------------------------
  228. //    FW_CCommand::SetCausesChange
  229. //----------------------------------------------------------------------------------------
  230. inline void FW_CCommand::SetCausesChange(Environment* ev, FW_Boolean causesChange)
  231. {
  232.     fCausesChange = causesChange;
  233. }
  234.  
  235. #if FW_LIB_EXPORT_PRAGMAS
  236. #pragma lib_export off
  237. #endif
  238.  
  239. #endif
  240.